﻿<script type="text/javascript" src="@Url.Content("/AutoUI/Scripts/mainType.js")"></script>
<body class="easyui-layout">
    <div data-options="region:'west',border:true,split:true,collapsible:true" title="类别" style="width:200px;padding:3px;">
        <ul id="dgTree" class="easyui-tree" url="/AutoUI/ConfigUIDef/MainType/GetTypeTree" data-options="dnd:true,onContextMenu: showContextMenu,onDblClick:beginEditNode,onAfterEdit:endEditNode,onSelect:selectNode,onBeforeDrop:onBeforeDrop,onDrop:onDrop"></ul>
    </div>
    <div data-options="region:'center'" style="border-top:0">
        <div id="tb">
            <table cellpadding="0" cellspacing="0" style="width: 100%">
                <tr>
                    <td>
                        <a href="#" class="easyui-linkbutton" iconcls="iconfont iconfont-jia1" plain="true" onclick="add()">增加</a>
                        <a href="#" class="easyui-linkbutton" iconcls="iconfont iconfont-shanchu" plain="true" onclick="removeit()">删除</a>
                    </td>
                </tr>
            </table>
        </div>
        <table id="mf_grid" class="easyui-datagrid" rownumbers="true" fit="true" pagination="true" fitcolumns="false" striped="true" border="false" idfield="Id"
               url="getlist" autorowheight="false" singleselect="false" toolbar="#tb">
            <thead>
                <tr>
                    <th data-options="field:'ck',checkbox:true"></th>
                    <th field="Code" width="150" halign='center'>
                        编号
                    </th>
                    <th field="Name" width="150" halign='center'>
                        名称
                    </th>
                    <th field="ModuleName" width="100" halign='center'>
                        数据库名
                    </th>
                    <th field="EntityName" width="200" halign='center'>
                        表名
                    </th>
                    <th field="BasicDefine" width="100" halign='center'>
                        基本设置
                    </th>
                    <th field="FlowGraph" width="100" halign='center'>
                        流程设计
                    </th>
                    <th field="IsPublish" width="100" halign='center' align="center">
                        是否已发布
                    </th>
                    <th field="ModifyTime" width="100" halign='center'>
                        最近修改时间
                    </th>
                </tr>
            </thead>
        </table>
    </div>
    <div id="mm" class="easyui-menu" style="width:120px;">
        <div onclick="appendNode()" data-options="iconCls:'iconfont iconfont-jia1'">增加</div>
        <div id="mmRemove" onclick="removeNode()" data-options="iconCls:'iconfont iconfont-shanchu'">删除</div>
        <div class="menu-sep"></div>
        <div onclick="expand()">展开</div>
        <div onclick="collapse()">折叠</div>
    </div>
</body>

<script>
    @Html.GetEnum(typeof(MF_WorkFlow.TrueFalseType))
    //addGridEnum("mf_grid", "IsPublish", TrueFalseType)
    addGridBtn('mf_grid', 'IsPublish', {
        onButtonClick: function (row, index) {
            publish(row);
        }, enumSourceVarName: TrueFalseType,JustShowLinkText: false
    });
    addGridDate('mf_grid', 'ModifyTime', 'yyyy-MM-dd');
</script>
<script>
    addGridLink('mf_grid', 'Name', '/WorkFlow/WFDef/Basic?FuncType=View');

    addGridLink('mf_grid', 'BasicDefine', '/WorkFlow/WFDef/Basic', {
        onFilter: function (e) {
            return e.IsPublish == 'false';
        },
        linkText: '基本设置', height: 300, width: 700, onDestroy: function (e) {
            if (e) {
                $("#mf_grid").datagrid('reload');
            }
        }
    });

    addGridBtn('mf_grid', 'FlowGraph', {
        linkText: '流程设计',
        onButtonClick: function (row, index) {
            var url = '/WorkFlow/WFDef/FlowGraph?Id=' + row.Id +'&Code=' + row.Code;
            if (row.IsPublish == 'true')
            {
                url += '&FuncType=View';
            }

            openWindow(url, {
                width: '70%', height: '70%',data:row.Detail
            });
        }
    });

    //addGridLink('mf_grid', 'FlowGraph', '/WorkFlow/WFDef/FlowGraph', {
    //    linkText: '流程设计', onFilter: function (e) {
    //        return e.IsPublish == 'false';
    //    },
    //});

    function publish(row) {
        if (row) {
            var url = 'Publish';

            var info = ''

            if (row.IsPublish == 'true') {
                info = '是否撤销发布?';
                addAjaxParam('bPublish', 'false');
            }
            else {
                info = '是否发布?';
                addAjaxParam('bPublish', 'true');
            }

            confirmBox(info, function (r) {
                if (r) {
                    addAjaxParam('id', row.Id);
                    commitAjax('Publish', {
                        CallBack: function (data) {
                            if (data) {
                                $("#mf_grid").datagrid('reload');
                                $("#mf_grid").datagrid('clearSelections');
                            }
                        }
                    });
                }
            })
        }
    }

    //删除
    function removeit() {
        //获取当前选中行
        var rows = $('#mf_grid').datagrid('getSelections');
        //如果不为空
        if (rows.length > 0) {
            confirmBox('是否删除?', function (r) {
                if (r) {
                    addAjaxParam('list', rows);
                    commitAjax('Delete', {
                        CallBack: function (data) {
                            if (data) {
                                msgBox(data);
                                //成功后刷新界面
                                $("#mf_grid").datagrid('reload');
                            }
                        }
                    });
                }
            })
        }
    }

    //增加
    function add() {
        openWindow('Basic', {
            width: '80%', height: '70%', onDestroy: function (data) {
                if (data) {
                    $("#mf_grid").datagrid('reload');
                }
            }
        });
    }

    //function add() {
    //    openWindow('EntityList', {
    //        width: 600, height: 400, onDestroy: function (data) {
    //            if (data) {
    //                addAjaxParam('data', data);
    //                var url = 'AddWorkFlow';
    //                commitAjax(url, {
    //                    CallBack: function (e) {
    //                        if (e) {
    //                            $("#mf_grid").datagrid('reload');
    //                        }
    //                    }
    //                })
    //            }
    //        }
    //    });
    //}

    function edit() {
        var row = $('#mf_grid').treegrid('getSelected');
        if (row) {
            openWindow('Form?id=' + row.Id, {
                width: 500, height: 280, onDestroy: function (data) {
                    if (data)
                        $("#mf_grid").datagrid('reload');
                }
            });
        }
    }
</script>

